﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using DefLib;

namespace GameUI
{
    public class MenuGame:WindowUI
    {

        int x_pad;
        int y_pad;
        public List<Button> l_button;

        public Button CreateButton(List<Texture2D> l_tt2d, string faceimg, float x, float y, int w, int h)
        {
            Sprite sp_bn = new Sprite();
            sp_bn.Create(l_tt2d, 0, 0, 0, 0);

            List<Sprite> l_sp_newgame = new List<Sprite>();
            // Button newgame
            List<Texture2D> l_tt2d_ng = new List<Texture2D>();
            l_tt2d_ng.Add(gDef.Content.Load<Texture2D>(faceimg));
            Sprite sp_n = new Sprite();
            sp_n.Create(l_tt2d_ng, 0, 0, 0, 0);
            l_sp_newgame.Add(sp_bn);
            l_sp_newgame.Add(sp_n);
            Button bt_ng = new Button();
            bt_ng.create(l_sp_newgame, x, y, w, h);
            return bt_ng;
        }
        public void create(float x, float y, int width, int height)
        {
            _x = x;
            _y = y;
            _w = width;
            _h = height;

            l_button = new List<Button>();
            // Canh lề cho button
            x_pad = _w/10;
            y_pad = _h/10;

           
            // Khởi tạo list texture
            List<Texture2D> l_tt2d = new List<Texture2D>();
            l_tt2d.Add(gDef.Content.Load<Texture2D>(@"Resource\button_normal"));
            l_tt2d.Add(gDef.Content.Load<Texture2D>(@"Resource\button_hover"));
            l_tt2d.Add(gDef.Content.Load<Texture2D>(@"Resource\button_click"));


            // Button newgame

            l_button.Add(this.CreateButton(l_tt2d, @"Resource\menu_text_newgame",
                _x + x_pad, _y + y_pad, _w - 2 * x_pad, (_w - 2 * x_pad) / 4));

            // Button Help
            l_button.Add(this.CreateButton(l_tt2d, @"Resource\menu_text_help",
                _x + x_pad, _y + 2 * y_pad + (_w - 2 * x_pad) / 4, _w - 2 * x_pad, (_w - 2 * x_pad) / 4));

            // Button Exit
            l_button.Add(this.CreateButton(l_tt2d, @"Resource\menu_text_exit",
                _x + x_pad, _y + 3 * y_pad + 2 * (_w - 2 * x_pad) / 4, _w - 2 * x_pad, (_w - 2 * x_pad) / 4));

            
        
        }
        public override void update(float x, float y, int w, int h)
        {
            base.update(x, y, w, h);
            for (int i = 0; i < l_button.Count; i++)
            {
                l_button[i].update(_x + x_pad,_y+(i+1)*y_pad+i*(_w - 2 * x_pad)/4,
                   _w - 2 * x_pad, (_w - 2 * x_pad) / 4);
            }

        }
        public override void draw(SpriteBatch spriteBatch)
        {
            for (int i = 0; i < l_button.Count; i++)
            {
                l_button[i].draw(spriteBatch);
            }
        }

    }
}
